package com.ruoyi.project.bas.basSupplier.controller;

import java.util.List;

import com.ruoyi.project.bas.product.domain.BasProduct;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.bas.basSupplier.domain.BasSupplier;
import com.ruoyi.project.bas.basSupplier.service.IBasSupplierService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 供应商基础信息Controller
 * 
 * @author qxq
 * @date 2023-05-30
 */
@Controller
@RequestMapping("/bas/basSupplier")
public class BasSupplierController extends BaseController
{
    private String prefix = "bas/basSupplier";

    @Autowired
    private IBasSupplierService basSupplierService;

    @GetMapping()
    public String basSupplier()
    {
        return prefix + "/basSupplier";
    }

    /**
     * 查询供应商基础信息列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasSupplier basSupplier)
    {
        startPage();
        List<BasSupplier> list = basSupplierService.selectBasSupplierList(basSupplier);
        return getDataTable(list);
    }

    /**
     * 导出供应商基础信息列表
     */
    @Log(title = "供应商基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasSupplier basSupplier)
    {
        List<BasSupplier> list = basSupplierService.selectBasSupplierList(basSupplier);
        ExcelUtil<BasSupplier> util = new ExcelUtil<BasSupplier>(BasSupplier.class);
        return util.exportExcel(list, "供应商基础信息数据");
    }

    /**
     * 下载模板
     */
    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate()
    {
        ExcelUtil<BasSupplier> util = new ExcelUtil<BasSupplier>(BasSupplier.class);
        return util.importTemplateExcel("供应商信息");
    }

    /**
     * 导入数据
     */
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<BasSupplier> util = new ExcelUtil<BasSupplier>(BasSupplier.class);
        List<BasSupplier> supplierList = util.importExcel(file.getInputStream());

        String message = basSupplierService.importSupplier(supplierList, updateSupport);
        return AjaxResult.success(message);
    }
    /**
     * 新增供应商基础信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存供应商基础信息
     */
    @Log(title = "供应商基础信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasSupplier basSupplier)
    {
        return toAjax(basSupplierService.insertBasSupplier(basSupplier));
    }

    /**
     * 修改供应商基础信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        BasSupplier basSupplier = basSupplierService.selectBasSupplierById(id);
        mmap.put("basSupplier", basSupplier);
        return prefix + "/edit";
    }

    /**
     * 修改保存供应商基础信息
     */
    @Log(title = "供应商基础信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasSupplier basSupplier)
    {
        return toAjax(basSupplierService.updateBasSupplier(basSupplier));
    }

    /**
     * 删除供应商基础信息
     */
    @Log(title = "供应商基础信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basSupplierService.deleteBasSupplierByIds(ids));
    }
}
